package jp.sourceforge.akjrcp.potrace;

import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import org.freehep.postscript.PSDebugger;
import org.freehep.postscript.PSInputFile;
import org.freehep.postscript.Processor;

public class FreehepUtils {

	public static void drawPostScript(Graphics2D g,int w,int h,File psFile) throws IOException{
		//graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		//graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		FreeHepGraphicsDevice device=new FreeHepGraphicsDevice(g,w,h);
		int page=1;
		double scale=1.0;
		int tx=0;
		int ty=0;
		boolean debug=false;
		
        Processor processor = new Processor(device,false);
        processor.setData(new PSInputFile(psFile.getAbsolutePath()));
        processor.setPageNo(page);
        processor.setScale(scale, scale);
        processor.setTranslation(tx, ty);
        if (debug) {
            PSDebugger debugger = new PSDebugger();
            processor.attach(debugger);
            debugger.showInFrame();
            processor.reset();
        } else {
            processor.process();
        }
	}
}
